#include<stdio.h>
#include<stdlib.h>
void main(int *p[],int n)
{
printf("\t List data structure \t\n Functions are \n1.append\n2.insert\n3.remove\n4.pop\n5.index\n6.extend\n7.count\n8.sort\n9.reverse\n10.exit\n11.display\n12.menu\nenter:");
int i=0,j=0,k=0,key,ab,*point,val,op;
printf("\tTo create initial list");
p=calloc(10000,sizeof(int));
point=realloc(*p,sizeof(int));
int *b,*pnt,*s,*st,num,pos,n3;
b=calloc(10000,sizeof(int));
pnt=realloc(*b,sizeof(int));
s=calloc(10000,sizeof(int));
st=realloc(*s,sizeof(int));

do
{
i++;
printf("\nenter element (0 to terminate):");
scanf("%d",&point[i]);
}while(point[i]!=0);
n=i;
for(i=0;i<n-1;i++)
{
printf("%d\t",point[i+1]);
}
while(op!=10)
{
printf("\nenter function number(10 to exit):");
scanf("%d",&op);
switch(op)
{
case 1:
printf("enter value to be appended:");
scanf("%d",&point[n]);
for(i=1;i<=n;i++)
{
printf("%d\t",point[i]);
}
n=n+1;
break;


case 2:printf("enter position at which number is to be inserted");
	scanf("%d",&pos);
	printf("enter number to insert");
	scanf("%d",&n3);
	if(pos>=n-1)
	printf("\ninvalid positon\n");
	else
	{	
	do{
	k++;
	}while(k!=pos+1);
	for(i=0;i<k;i++)
	{
	pnt[i]=point[i];
	}
	for(i=k+1;i<=n;i++)
	{
	pnt[i]=point[i-1];
	}	
	pnt[k]=n3;
	for(i=1;i<=n;i++)
	{
	point[i]=pnt[i];
	printf("\t%d",point[i]);
	}
	n++;
	}	
	break;
case 3:printf("enter number to be removed");
	scanf("%d",&val);
	j=0;	
	for(i=0;i<n;i++)
	{
	if(point[i]==val)
	{
	ab=i;
	break;
	}
	else
	{
	st[j]=point[i];
	j++;
	}
	}
	
	for(i=ab+1;i<n;i++)
	{
	st[i-1]=point[i];
	}
	if(j>=n)
	{printf("number does not exist");
	}
	else
	{for(i=1;i<n-1;i++)
	{
	point[i]=st[i];
	printf("%d\t",point[i]);	
	}
	if(j<=n)		
	n=n-1;
	}
	break;
case 4:printf("enter the position of the number to be popped");
	scanf("%d",&pos);
	j=0;	
	if(pos>=n-1)
	printf("\ninvalid positon\n");
	else
	{
	printf(" %d ",point[pos+1]);
	for(i=0;i<=pos;i++)
	{
	st[i]=point[i];
	}
	for(i=pos+2,j=pos+1;i<n,j<n;i++,j++)
	{
	st[j]=point[i];
	}
	for(i=0;i<n-1;i++)
	{
	point[i]=st[i];
	}
	n--;
	}
	break;

case 5:printf("enter number to find the index");
       scanf("%d",&val);
	for(i=0;i<n;i++)
	{
	if(point[i]==val)
	{
	printf("%d",i-1);
	break;	
	}
	else	
	{
	continue;
	}
	}
	if(i>=n)
	printf("number does not exist");
	break;

case 6:printf("enter list to be extended\n");
	i=0;
	do
	{
	i++;
	printf("enter element(0 to terminate)");
	scanf("%d",&pnt[i]);
	}while(pnt[i]!=0);
	num=i;
	for(j=n,i=1;j<n+num-1,i<=num-1;j++,i++)
	{
	point[j]=pnt[i];
	}
	for(i=1;i<n+num-1;i++)
	{
	printf(" %d\t",point[i]);
	}
	n=n+num-1;
	break;
	
case 7: printf("enter number to be counted");
	scanf("%d",&val);	
	j=0;	
	for(i=0;i<n;i++)
	{
	if(point[i]==val)
	{
	pnt[j]=val;
	j=j+1;
	}
	}
	printf("%d",j);
	if(j>=n)
	printf("0");
	break;

case 8:for(j=1;j<n;j++)
	{
	key=point[j];
	i=j-1;
	while(i>=0&&point[i]>key)
	{
	point[i+1]=point[i];
	i=i-1;
	}
	point[i+1]=key;
	}
	for(k=1;k<n;k++)
	{
	printf(" %d ", point[k]); 
	}
	break;

case 9:for(i=0,j=n;i<n,j>=0;i++,j--)
	{
	pnt[j]=point[i];
	}
	for(i=1;i<n;i++)
	{
	point[i]=pnt[i];
	printf(" %d ",point[i]);
	}
	break;
case 10: break;

case 11:for(i=1;i<n;i++)
	printf(" %d ",point[i]);
	break;

case 12: printf("\t List data structure \t\n Functions are \n1.append\n2.insert\n3.remove\n4.pop\n5.index\n6.extend\n7.count\n8.sort\n9.reverse\n10.exit\n11.display\n12.menu\nenter:");
break;

}
}
}


